import { defineStore } from "pinia";
import { store } from "../utils";
import { getDictionary } from "@/api/basicArchives/dictionaries";

export const useDict = defineStore({
  id: "pure-dict",
  state: () => ({
    dictList: ""
  }),
  getters: {
    getDictList(state) {
      return state.dictList;
    }
  },
  actions: {
    /** 获取数据字典 */
    async getDictlist(param) {
      return new Promise<any>((resolve, reject) => {
        getDictionary(param)
          .then(data => {
            localStorage.setItem("dictList", JSON.stringify(data.data.records));
            resolve(data);
          })
          .catch(error => {
            reject(error);
          });
      });
    }
  }
});

export function useDictStoreHook() {
  return useDict(store);
}
